﻿using KhoaLuan.Areas.Admin.ActionFilters;
using KhoaLuan.Areas.Admin.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace KhoaLuan.Areas.Admin.Controllers
{
    [Security]
    public class KiemKeController : Controller
    {
        //
        // GET: /Admin/KiemKe/
        LuanVanEntities db = new LuanVanEntities();
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult byCategory()
        {
            ViewBag.Title = "Kiểm Kê theo chủng loại sản phẩm";
            var list = db.Products
                .GroupBy(p => p.Category)
                .Select(g => new ReportInfo
                {
                    Group = g.Key.Link,
                    Sum = g.Sum(p => p.UnitPrice * p.Quantity),
                    Count = g.Sum(p => p.Quantity),
                    Min = g.Min(p => p.UnitPrice),
                    Max = g.Max(p => p.UnitPrice),
                    Avg = g.Average(p => p.UnitPrice)
                });
            return View("KiemKe", list);
        }
        public ActionResult bySupplier()
        {
            ViewBag.Title = "Kiểm kê theo nhà sản Xuất";
            var list = db.Products.GroupBy(p => p.Supplier).Select(
                g => new ReportInfo
                {
                    Group = g.Key.Name,
                    Sum = g.Sum(p => p.UnitPrice * p.Quantity),
                    Count = g.Sum(p => p.Quantity),
                    Min = g.Min(p => p.UnitPrice),
                    Max = g.Max(p => p.UnitPrice),
                    Avg = g.Average(p => p.UnitPrice)
                });
            return View("KiemKe", list);
        }
	}
}